package com.zhl.study.base;

import com.zhl.study.enums.IEnum;
import com.zhl.study.enums.SystemEnums;

/**
 * @description 接口响应工厂
 * @Author: z156940l@outlook.com
 * @className ResponseFactory
 * @Date: 2023/4/28 10:14
 */
public class ResponseFactory {

    public static<T> Result<T> ok(){
        return new Result<>(SystemEnums.SUCCESS);
    }

    public static<T> Result<T> ok(T data){
        return new Result<>(SystemEnums.SUCCESS, data);
    }

    public static<T> Result<T> fail(){
        return new Result<>(SystemEnums.FAIL);
    }

    public static<T> Result<T> fail(T data){
        return new Result<>(SystemEnums.FAIL, data);
    }

    public static<T> Result<T> fail(IEnum iEnum, T data){
        return new Result<>(String.valueOf(iEnum.getCode()), String.valueOf(iEnum.getMsg()), data);
    }

    public static<T> Result<T> fail(IEnum iEnum, String msg, T data){
        return new Result<>(String.valueOf(iEnum.getCode()), msg, data);
    }
}

